package com.xxx.file;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/22  11:00
 * @Copyright
 */
public class FileWriterDome {
    public static void main(String[] args) {
        //m1()
        //m2();

        //jdk.7 try-with-resource

        try ( FileWriter fileWriter = new FileWriter("a.txt",true))
        {
            fileWriter.write("abcdfzbdf");
            // fileWriter.flush();
            // fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }



    }

    private static void m2() {
        FileWriter fileWriter = null;
        try {
            fileWriter = new FileWriter("a.txt");
            fileWriter.write("abc");
            //fileWriter.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void m1() throws IOException {
        FileWriter fileWriter = new FileWriter("a.txt");
        fileWriter.write("abc");
        //fileWriter.flush();
        fileWriter.close();
    }
}
